<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<script type="text/javascript">
$("document").ready(function(){
	
	var params ={ID:'${ID}',MODULE_NO:'${MODULE_NO}',edit:'${edit}'};
	
	if(params.edit == 'false'){

		$("#fileUpload").remove();
		
		$(".fRemove").remove();
		
	}else{

		$("#upload").uploadify({   
			
			script: basepath+"/${param.namespace}/upload",
        
			fileDataName : 'file', 
			
			scriptData:params,
			
			queueID: 'fileQueue',
			
			fileExt:"${param.fileExt}",
			
			fileDesc:"${param.fileDesc}",
        
			onComplete:function(event, ID, fileObj, response, data){
				
			   var array=new Array();
			   
			   array.push('<li namespace="${param.namespace}" fid ="${param.ID}" fname="'+response+'" style="height:30px;">');
			   
			   array.push('<a class="fList" href="javascript:void(0);">'+response+'</a><a class="fRemove" href="javascript:void(0);" style="float:right;"></a>');
			   
			   array.push('</li>');
			   
			   $("#fileList").append(array.join(""));
			   
			   app.popWins["popWin"].close();
			   
			   app.module.reloadList();
			   
			}
		}); 
	}
	

	$(".fRemove").die("click").live("click",function(){
		
		var li = $(this).closest("li");
		
		params.filename=li.attr("fname");
		
		util.confirm("确定要删除这些附件吗？",function(){
			
			$.post(basepath+"/${param.namespace}/fileRemove",params,function(data){
				
				if(data.success){
					
					util.alert("文件删除成功！","succeed");
					
					$(li).remove();
					
				}else{
					
					util.alert("文件删除失败！","error");
				}
				
			});
			
		});
		
	});
	
	$(".fList").die("click").live("click",function(){
		
		var li = $(this).closest("li");
		
		filename=encodeURI(li.attr("fname"));

		filename=encodeURI(filename);
		
		window.open(basepath+'/${param.namespace}/download?ID='+params.ID+"&filename="+filename+'&token='+params.token+"&MODULE_NO="+params.MODULE_NO,'_blank');
	
	});
});
</script>
<div style="height:300px;margin:10px;">
	<ul id="fileList" style="width:300px;height:200px;">
	 	<c:forEach items="${files}" var="file">
	        <li namespace="${param.namespace}" fid ="${param.ID}" fname="${file.filename}.${file.filetype}">
	       	    <a class="fList" href="javascript:void(0);">${file.filename}.${file.filetype}</a><a class="fRemove" href="javascript:void(0);"></a>
	        </li>	
	    </c:forEach>
	</ul>
	<div id="fileUpload" style="width:300px;height:80px;">
		
		<div id="fileQueue" style="width:275px;height:50px;">
		
		</div>
			    
		<div style="text-align:right;padding-right:10px;">
			
			<input id="upload" name=file type="file" />
			
		</div>
	
	</div>
</div>